package csel.model;

import csel.model.Direction;

public class Door extends Item
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private TakeableItem myKey;
	private boolean locked;
	private Entity lastToucher;
	Direction lockedDirection;
	Direction unlockedDirection;
	public Door(TakeableItem key, String type, Direction lockedDirection)
	{
		this.typeId = type;
		this.myKey = key;
		this.lockedDirection = lockedDirection;
		switch (lockedDirection)
		{
		case SOUTH : unlockedDirection = Direction.SOUTHWEST; break;
		case WEST : unlockedDirection = Direction.NORTHWEST; break;
		case NORTH : unlockedDirection = Direction.NORTHEAST; break;
		case EAST : unlockedDirection = Direction.SOUTHEAST; break;
		default : unlockedDirection = Direction.SOUTHWEST;
		}
		this.direction = lockedDirection;
	}
	public boolean touch(Entity e)
	{
		if(e.getInventory().hasItem(myKey))
		{
			this.direction = unlockedDirection;
			locked = false;
		}
		else
		{
			this.direction = lockedDirection;
			locked = true;
		}
		lastToucher = e;
		return(locked);
	}
	public boolean isImpassable()
	{
		if(lastToucher==null)
		{
			return(true);
		}
		System.out.println("[MODEL] here i am "+ locked);
		return(locked||touch(lastToucher));
	}

}
